package main

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

type User struct {
	gorm.Model
	Name    string `json:"name" gorm:"size:50;default:'小明'"`
	Age     int64  `json:"age"`
	Address string `json:"address"`
}

func (*User) find(u string) {
	fmt.Println("查询用户")
}

var GoalVon gorm.DB

func main() {
	open, err := gorm.Open("mysql", "root:123456@/test?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		return
	}
	fmt.Println("链接成功")

	GoalVon := open
	GoalVon.DB().SetMaxIdleConns(10)
	GoalVon.SingularTable(true)
	GoalVon.AutoMigrate(new(User))
	u := User{}
	u.find("name ")

}
